package empleadoAdministrativo;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;



import misc.Logica;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NuevoRequisito_GUI extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JLabel lblCodigo;
	private JTextField txtCodigo;
	private JButton btnCancelar;
	private JButton btnAceptar;
	private JTextField txtDescripcion;
	private JLabel lblDescripcion;
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	private AdminRequisito_GUI padre;
	private Logica logica;
	
	public NuevoRequisito_GUI(AdminRequisito_GUI padre, Logica logica) {
		super();
		initGUI();
		this.padre=padre;
		this.logica=logica;
	}
	
	public void setProxID() {
		txtCodigo.setText(Integer.toString(logica.getLastInsertIDRequerimientos()));
		txtDescripcion.requestFocus();
		}
	
	
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Nuevo Requisito");
			{
				lblCodigo = new JLabel();
				getContentPane().add(lblCodigo);
				lblCodigo.setText("Código");
				lblCodigo.setBounds(43, 40, 62, 16);
			}
			{
				txtCodigo = new JTextField();
				getContentPane().add(txtCodigo);
				txtCodigo.setBounds(105, 37, 60, 23);
				txtCodigo.setEditable(false);
			}
			{
				lblDescripcion = new JLabel();
				getContentPane().add(lblDescripcion);
				lblDescripcion.setText("Descripción [*]");
				lblDescripcion.setBounds(43, 87, 122, 16);
			}
			{
				txtDescripcion = new JTextField();
				getContentPane().add(txtDescripcion);
				txtDescripcion.setBounds(43, 115, 363, 23);
			}
			{
				btnAceptar = new JButton();
				getContentPane().add(btnAceptar);
				btnAceptar.setText("Aceptar");
				btnAceptar.setBounds(91, 182, 91, 23);
				btnAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						btnAceptarActionPerformed(evt);
					}
				});
			}
			{
				btnCancelar = new JButton();
				getContentPane().add(btnCancelar);
				btnCancelar.setText("Cancelar");
				btnCancelar.setBounds(253, 182, 89, 23);
				btnCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						btnCancelarActionPerformed(evt);
					}
				});
			}
			pack();
			this.setSize(452, 280);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void btnAceptarActionPerformed(ActionEvent evt) {
		 
		if (txtDescripcion.getText().equals("")) {
			JOptionPane.showMessageDialog(null,"La descripción no puede ser vacía", "Error", JOptionPane.ERROR_MESSAGE);
		}
		else {
		
		int respuesta = JOptionPane.showConfirmDialog(null, "¿Confirma la operación?", "Agregar requisito",
                 JOptionPane.YES_NO_OPTION);
			
			 //Confirmacion afirmativa, sino volvemos a la pantalla
			 if(respuesta==JOptionPane.YES_OPTION){
		logica.crearRequisito(txtDescripcion.getText().toLowerCase());
		this.setVisible(false);
		
		padre.mostrarRequisitos();
			 }
	}
	}
	
	private void btnCancelarActionPerformed(ActionEvent evt) {
		this.dispose();
		txtDescripcion.setText("");
	}

}
